<?php
class ShareController extends AppController
{
	
	var $autoRender = false;
    var $uses = array('Share_goods','Share_collocation');
    var $layout = 'default';
    
    function goods()
    {
//    	$user_id = $_SESSION['user_id'];
//    	$url = init_web_para( 'url', '' );
    	$url = 'http://www.baidu.com';
    	$user_id = 1;
    	if( strlen( $url ) > 0 && ( false !== strpos( $url, 'http://' ) || false !== strpos( $url, 'www.' ) ) )
    	{
    		$goods_id = get_goods_id();
    		$curr_time = date( 'Y-m-d H:i:s' );
			$data = array(
				'id' => null,
				'user_id' => $user_id,
				'goods_id' => $goods_id,
				'url' => $url,
				'create_time' => $curr_time,
				'update_time' => $curr_time
			);
			$ret = $this->Share_goods->save( $data );
    	}
    }
 	function collocation()
    {
    //  $user_id = $_SESSION['user_id'];
//    	$url = init_web_para( 'url', '' );

		$col_name = init_web_para( 'col_name', '' );
		$describe = init_web_para( 'describe', '' );
    	$images = 'dddddd';
    	$user_id = 1;
    	if( strlen( $images ) > 0 )
    	{
    		$curr_time = date( 'Y-m-d H:i:s' );
			$data = array(
				'id' => null,
				'user_id' => $user_id,
				'goods_ids' => $this->set_goods_batch( 1 ),
				'col_id' => get_collocation_id(),
				'col_name' => $col_name,
				'describe' => $describe,
				'images' => $images,
				'create_time' => $curr_time,
				'update_time' => $curr_time
			);
			$ret = $this->Share_collocation->save( $data );
    	}
    }
    function set_goods_batch( $type )
    {
    	$goods_ids  = '';
    	//  $user_id = $_SESSION['user_id'];
    	$user_id = 1;
    	$url_array = array( 'http://www.baidu.com','http://www.baidu.com','http://www.baidu.com' );
    	foreach ( $url_array as $url )
    	{
	    	if( strlen( $url ) > 0 && ( false !== strpos( $url, 'http://' ) || false !== strpos( $url, 'www.' ) ) )
	    	{
	    		$goods_id = get_goods_id();
	    		$curr_time = date( 'Y-m-d H:i:s' );
				$data = array(
					'id' => null,
					'type' => $type,
					'user_id' => $user_id,
					'goods_id' => $goods_id,
					'url' => $url,
					'create_time' => $curr_time,
					'update_time' => $curr_time
				);
				$ret = $this->Share_goods->save( $data );
				if( $ret === true )
				{
					$goods_ids .= $goods_id.',';
				}
	    	}
    	}
    	return $goods_ids;
    }
}